package zhao.exmaple;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.functions.RuntimeContext;
import org.apache.flink.runtime.state.FunctionInitializationContext;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.datagen.DataGenerator;
import org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSource;
import org.apache.flink.streaming.api.functions.source.datagen.RandomGenerator;

import java.util.Random;

public class GeneratorSourceDemo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataGeneratorSource dataGeneratorSource = new DataGeneratorSource(new RandomGenerator() {
            @Override
            public Integer next() {
                Random random = new Random();
                int randomNumber = random.nextInt(10) + 1;
                return randomNumber;
            }
        }, 1, 10L);

        DataStreamSource dataStreamSource = env.addSource(dataGeneratorSource);
        dataStreamSource.print();
        env.execute();

    }
}
